home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1996 June / Software of the Month Club 1996 June.iso / pc / dos / dtp / display / util / vesainfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-27  |  5.7 KB  |  182 lines

  1. /**
  2.  ** VESAINFO.C ---- test program to print VESA BIOS information
  3.  **
  4.  ** Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5.  ** Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6.  ** Copyright (C) 1993 Grzegorz Mazur, gbm@ii.pw.edu.pl
  7.  ** Modified by Jih-Shin Ho to support VESA 2.0
  8.  **
  9.  ** This file is distributed under the terms listed in the document
  10.  ** "copying.dj", available from DJ Delorie at the address above.
  11.  ** A copy of "copying.dj" should accompany this file; if not, a copy
  12.  ** should be available from where this file was obtained.  This file
  13.  ** may not be distributed without a verbatim copy of "copying.dj".
  14.  **
  15.  ** This file is distributed WITHOUT ANY WARRANTY; without even the implied
  16.  ** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17.  **/
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <dos.h>
  22.  
  23. #include "pieces/vesainfo.c"
  24.  
  25. void printinfo(VgaInfoBlock *vgainfo)
  26. {
  27.     char  far *sp = vgainfo->OEMStringPtr;
  28.     short far *mp = vgainfo->VideoModePtr;
  29.  
  30.     printf("VESASignature:\t\"%c%c%c%c\"\n",
  31.         vgainfo->VESASignature[0],
  32.         vgainfo->VESASignature[1],
  33.         vgainfo->VESASignature[2],
  34.         vgainfo->VESASignature[3]
  35.     );
  36.     printf("VESAVersion:\t%d.%d\n",
  37.         VESA_VERSION_MAJOR(VESAversion),
  38.         VESA_VERSION_MINOR(VESAversion)
  39.     );
  40.     printf("OEMStringPtr:\t\"");
  41.     while(*sp != '\0') putchar(*sp++);
  42.     printf("\"\nCapabilities:\t%ld\n",vgainfo->Capabilities);
  43.     printf("VideoModePtr:\t%Fp\n",mp);
  44.     printf("Video Modes:\t");
  45.     while(*mp != (-1)) printf("0x%x ",*mp++);
  46.     printf("\n");
  47.     if(VESAversion >= VESA_VERSION(1,2)) {
  48.         printf("Memory Size:\t%d*64KBytes\n",vgainfo->MemorySize);
  49.     }
  50.     printf("\n");
  51.  
  52. }
  53.  
  54. /*
  55.   The preprocessor of TC 2.0 is strange
  56. */
  57. #define DEFBIT(bit) { bit, #bit }
  58.  
  59. typedef struct {
  60.     int  bit;
  61.     char *name;
  62. } bitdef;
  63.  
  64. bitdef modeattrbits[] = {
  65.     DEFBIT(MODE_SUPPORTED),
  66.     DEFBIT(MODE_EXTINFO),
  67.     DEFBIT(MODE_SUPBIOS),
  68.     DEFBIT(MODE_ISCOLOR),
  69.     DEFBIT(MODE_ISGRAPHICS),
  70.     DEFBIT(MODE_NO_WINDOW),
  71.     DEFBIT(MODE_LINEAR_FRAME),    
  72.     { 0 }
  73. };
  74.  
  75. bitdef winattrbits[] = {
  76.     DEFBIT(WIN_SUPPORTED),
  77.     DEFBIT(WIN_READABLE),
  78.     DEFBIT(WIN_WRITABLE),
  79.     { 0 }
  80. };
  81.  
  82. bitdef memorymodels[] = {
  83.     DEFBIT(MODEL_TEXT),
  84.     DEFBIT(MODEL_CGA),
  85.     DEFBIT(MODEL_HERC),
  86.     DEFBIT(MODEL_4PLANE),
  87.     DEFBIT(MODEL_PACKED),
  88.     DEFBIT(MODEL_256_NC),
  89.     DEFBIT(MODEL_DIRECT),
  90.     { 0 }
  91. };
  92.                  
  93. void printbits(int value,bitdef *def)
  94. {
  95.     int prev = 0;
  96.  
  97.     while(def->bit != 0) {
  98.          if(value & def->bit) {
  99.         if(prev) printf(" | ");
  100.         printf(def->name);
  101.         prev = 1;
  102.         }
  103.         def++;
  104.     }
  105.     if(!prev) printf("0");
  106.     printf("\n");
  107. }
  108.  
  109. char *getmodelname(int model)
  110. {
  111.     static char temp[50];
  112.  
  113.     if(model < 0) return(sprintf(temp,"Invalid model [%d]",model),temp);
  114.     if(model <= MODEL_DIRECT) return(memorymodels[model].name);
  115.     if(model <= 15) return(sprintf(temp,"VESA model [0x%02x]",model),temp);
  116.     return(sprintf(temp,"OEM model [%0x2x]",model),temp);
  117. }
  118.  
  119. void printmodeinfo(int mode,ModeInfoBlock *modeinfo)
  120. {
  121.     printf("Mode 0x%x is supported\n",mode);
  122.     printf("  ModeAttributes:   ");
  123.     printbits(modeinfo->ModeAttributes,modeattrbits);
  124.     printf("  WinAAttributes:   ");
  125.     printbits(modeinfo->WinAAttributes,winattrbits);
  126.     printf("  WinBAttributes:   ");
  127.     printbits(modeinfo->WinBAttributes,winattrbits);
  128.     printf("  WinGranularity:   %d\n",modeinfo->WinGranularity);
  129.     printf("  WinSize:          %d\n",modeinfo->WinSize);
  130.     printf("  WinASegment:      0x%04x\n",modeinfo->WinASegment);
  131.     printf("  WinBSegment:      0x%04x\n",modeinfo->WinBSegment);
  132.     printf("  WinFuncPtr:       \%Fp\n",modeinfo->WinFuncPtr);
  133.     printf("  BytesPerScanLine: %d\n",modeinfo->BytesPerScanLine);
  134.     if(!(modeinfo->ModeAttributes & MODE_EXTINFO)) return;
  135.     printf("  XResolution:      %d\n",modeinfo->XResolution);
  136.     printf("  YResolution:      %d\n",modeinfo->YResolution);
  137.     printf("  XCharSize:        %d\n",modeinfo->XCharSize);
  138.     printf("  YCharSize:        %d\n",modeinfo->YCharSize);
  139.     printf("  NumberOfPlanes:   %d\n",modeinfo->NumberOfPlanes);
  140.      printf("  BitsPerPixel:     %d\n",modeinfo->BitsPerPixel);
  141.     printf("  NumberOfBanks:    %d\n",modeinfo->NumberOfBanks);
  142.     printf("  MemoryModel:      %d (%s)\n",modeinfo->MemoryModel,getmodelname(modeinfo->MemoryModel));
  143.     printf("  BankSize:         %d\n",modeinfo->BankSize);
  144.     printf("  NumImagePages     %d\n",modeinfo->NumImagePages);
  145.     if(VESAversion < VESA_VERSION(1,2)) return;
  146.     printf("  RedMaskSize:      %d\n",modeinfo->RedMaskSize);
  147.     printf("  RedMaskPos:       %d\n",modeinfo->RedMaskPos);
  148.     printf("  GreenMaskSize:    %d\n",modeinfo->GreenMaskSize);
  149.     printf("  GreenMaskPos:     %d\n",modeinfo->GreenMaskPos);
  150.     printf("  BlueMaskSize:     %d\n",modeinfo->BlueMaskSize);
  151.     printf("  BlueMaskPos:      %d\n",modeinfo->BlueMaskPos);
  152.     printf("  ReservedMaskSize: %d\n",modeinfo->ReservedMaskSize);
  153.     printf("  ReservedMaskPos:  %d\n",modeinfo->ReservedMaskPos);
  154.     printf("  DirectScreenMode: %d\n",modeinfo->DirectScreenMode);
  155.     if(VESAversion < VESA_VERSION(2,0)) return;        
  156.         if (modeinfo->ModeAttributes & MODE_LINEAR_FRAME)
  157.           printf("  PhysBasePtr:      %08lx\n",modeinfo->PhysBasePtr);
  158.  
  159. }
  160.  
  161. void main(void)
  162. {
  163.     VgaInfoBlock  *vb;
  164.     ModeInfoBlock *mb;
  165.     if((vb = VESAgetInfo()) != NULL) {
  166.         static short modes[1000];
  167.         short far *modeptr = vb->VideoModePtr;
  168.         short *mdp = modes;
  169.         int mode;
  170.         printinfo(vb);
  171.         while((*mdp++ = *modeptr++) != (-1)) ;
  172.         mdp = modes;
  173.         while((mode = *mdp++) != (-1)) {
  174.         if((mb = VESAgetModeInfo(mode)) != NULL) printmodeinfo(mode,mb);
  175.         else printf("Mode 0x%x IS NOT SUPPORTED!\n",mode);
  176.         }
  177.     }
  178.     else printf("VESA BIOS extensions not found\n");
  179.     exit(0);
  180. }
  181.  
  182.